package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.Dept;
import com.itheima.service.ClazzService;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public void add(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.add(clazz);
    }

    @Override
    public List<Clazz> selectAll(Clazz clazz, Integer page, Integer size) {
        return clazzMapper.queryClazzs(clazz,page,size);
    }

    @Override
    public void delete(Integer id) {
        clazzMapper.deleteById(id);//重新定义的一个方法根据id删除部门
    }

    @Override
    public Clazz getById(Integer id) {
         return clazzMapper.getById(id);
    }

    @Override
    public void update(Clazz clazz) {
        //1.补全基础属性
        clazz.setUpdateTime(LocalDateTime.now());
        //2.更新数据
      clazzMapper.update(clazz);
    }

//    @Override
//    public List<Clazz> selectAll(Clazz clazz) {
//        return clazzMapper.queryClazzs(String name,
//                @Param("begin") LocalDate begin,
//                @Param("end") LocalDate end,
//        @Param("page") int page,
//        @Param("pageSize") int pageSize);
//    }

    /*@Override
    public List<Clazz> selectAll(Clazz clazz) {
        return selectAll(clazz);
    }

    @Override
    public PageInfo<Clazz> getByBage(Clazz clazz, Integer page, Integer size) {
        PageHelper.startPage(page,size);

        List<Clazz> clazzList = this.selectAll(clazz);

        return PageHelper.of;
    }*/
}
